package com.tarena.lbs.coupon.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.coupon.dao.mapper.CouponMapper;
import com.tarena.lbs.coupon.dao.repository.CouponRepository;
import com.tarena.lbs.coupon.pojo.po.CouponPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CouponRepositoryImpl implements CouponRepository {
    @Autowired
    private CouponMapper couponMapper;

    @Override
    public PageInfo<CouponPO> pageList(Integer Busid) {
        QueryWrapper<CouponPO> queryWrapper = new QueryWrapper<>();
        if (Busid != null) {
            queryWrapper.eq("business_id", Busid);
        }
        List<CouponPO> list =couponMapper.selectList(queryWrapper);
        PageResult<CouponPO> pageResult = new PageResult<>();
        pageResult.setObjects(list);
        pageResult.setTotal(couponMapper.selectCount(queryWrapper));
        return new PageInfo<>(list);
    }

    @Override
    public void Insert(CouponPO couponPO) {
        couponMapper.insert(couponPO);
    }

    @Override
    public CouponPO selectById(Integer id) {
        return couponMapper.selectById(id);
    }
}
